<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$templist=$this->plugin_setting('img');
if(!$templist || count($templist)<2){
	$templist=array(
		array('on'=>1,'img'=>'../addons/jy_invitation/templist/image_1_nail.jpg'),
		array('on'=>1,'img'=>'../addons/jy_invitation/templist/image_2_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_3_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_4_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_5_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_6_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_7_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_8_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_9_nail.jpg'),
		array('on'=>0,'img'=>'../addons/jy_invitation/templist/image_10_nail.jpg'),
	);
	$this->plugin_setting('img',$templist);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_invitation_list',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$v){
		$v['createtime']=date('Y/m/d H:i:s',$v['createtime']);
		$v['url']=custom_url('jy_invitation/index/detail/id='.$v['id'],true);
		$v['url1']=array('action'=>'post','plugin'=>'jy_invitation','query'=>'id='.$v['id']);
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'邀请卡列表'),
			array('plugin'=>'jy_invitation','action'=>'post','op'=>'edit','title'=>'添加'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(			
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'scan','title'=>'扫描数','type'=>'string'),
			array('name'=>'follow','title'=>'关注数','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),
		'action'=>array(
			array('name'=>'url1','title'=>'编辑','type'=>'href'),

		)
		),
		'search_one'=>array('name'=>'title','help'=>'标题','add'=>false),
	);
	$return['status']=array('0'=>'禁用','1'=>'启用');
	$return['htmls']=$htmls;
	exi($return);
}
/*if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_invitation_list',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'邀请卡信息',
		'tabs'=>array(
			array('op'=>'list','title'=>'邀请卡列表'),
			array('op'=>'formlist','title'=>'添加/编辑'),
		),
		'edit'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['status']=array('0'=>'禁用','1'=>'启用');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'status'=>trim($postdata['status']),
		'content'=>trim($postdata['content'])
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_invitation_list',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('留言修改成功！');
	}else{
		exi('没有找到相关留言');
	}
}*/
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_invitation_list',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_invitation_list',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
